<?php
	/**
	 * 修改玩家个人信息
	 */
    class EditPersonalInfo extends APIBase {
		
		public $tag = "EditPersonalInfo";
    	public $isLogin = true;
		
		public function before() {
			$this->initCacheRedis();
			$this->initMysql();
			return true;
		}
		public function logic() {
			$uid = $this->uid;
			if(!isset($this->param['headimgindex']) && $this->param['headimgindex'] == ''){
				$this->returnError(301,'参数错误');
			}
			if(!isset($this->param['sex']) && $this->param['sex'] == ''){
				$this->returnError(301,'参数错误');
			}
			if(!isset($this->param['name']) && $this->param['name'] == ''){
				$this->returnError(301,'参数错误');
			}
			$headimgindex = (int)$this->param['headimgindex'];
			$sex = (int)$this->param['sex'];

			if(!isset(Config::$headimgList["headimg_$sex"])){
				$this->returnError(301,'参数错误');
			}
			if(!isset(Config::$headimgList["headimg_$sex"][$headimgindex])){
				$this->returnError(301,'参数错误');
			}
			$faceUrl = Config::$pic_prefix.Config::$headimgList["headimg_$sex"][$headimgindex];
			$nickname = filter_emoji($this->param['name']);
			$this->data_redis->hMset('hu:'.$uid,array('name'=>$nickname,'sex'=>$sex,'avater_url'=>$faceUrl));
			$this->returnData(array('name'=>$nickname,'sex'=>$sex,'avater_url'=>$faceUrl));
		}
		
        public function after() {
			$this->deinitCacheRedis();
		}
    }
?>
